package com.amado.course49AnonymousClass;

import java.util.ArrayList;
import java.util.List;

public class S04StudentHandle {
	static List<Student> studentList = new ArrayList();

	public static void main(String[] args) {
		studentList.add(new Student("张三", 11));
		studentList.add(new Student("李四", 20));
		studentList.add(new Student("张三", 31));
		studentList.add(new Student("王五", 41));
		S04StudentHandle studentHandle = new S04StudentHandle();
		//排序 List.sort()，过滤java.io.File.listFiles()
		List<Student> reutrnStudent = studentHandle.listStudent(new StudentFilter() {
			@Override
			public boolean accept(Student student) {
				if (student.getAge() != null && student.getAge() > 10 && student.getName().contains("王")) {
					return true;
				}
				return false;
			}
		});
		for (Student stu : reutrnStudent) {
			System.out.println(stu);
		}
	}

	public List<Student> listStudent(StudentFilter filter) {
		List<Student> newList = new ArrayList();
		for (Student student : studentList) {
			//是否满足条件
			if (filter.accept(student)) {
				newList.add(student);
			}
//			if (student.getAge() != null && student.getAge() > 10 && student.getName().contains("王")) {
//				newList.add(student);
//			}
		}
		return newList;
	}

	public List<Student> listStudent() {
		return studentList;
	}
}
